package com.conversationboard.view;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.TimeZone;

import com.conversationboard.model.User;

public class TimeZoneDropDownDisplay {

    public static String display(User user) {

        String[] initialTimeZones = TimeZone.getAvailableIDs();
        Arrays.sort(initialTimeZones);

        List<String> timeZones = new ArrayList<String>();

        /* Remove some troublesome timezone settings */
        
        for (String timeZone : initialTimeZones) {
            if (!timeZone.contains("SystemV")) {
                timeZones.add(timeZone);
            }
        }

        timeZones.remove("Europe/Jersey");

        StringBuilder buffer = new StringBuilder();

        buffer.append("<select class='smalltextbox' name='timezone'>");

        buffer.append("<option>");

        if (user != null) {
            buffer.append(user.getPreferences().getTimeZone().getID());
        } else {
            buffer.append("Europe/London");
        }
        
        buffer.append("</option>");

        for (String timeZone : timeZones) {
            buffer.append("<option>");
            buffer.append(timeZone);
            buffer.append("</option>");
        }

        buffer.append("</select>");

        return buffer.toString();
    }

}
